<?php
class insert_db extends CI_Model{

    public function __construct()
    {
        // Call the Model constructor
        $this->load->database();
    }
    
    public function get_product_branch($id)
    {
        $query = $this->db->query("SELECT *
                                   FROM loai
                                   WHERE idLoai = $id
                                    ");
        return $query->result();
    }
    
    public function check_product_name($id)
    {
        $query = $this->db->query("SELECT TenSP
                                   FROM sanpham
                                   WHERE ID = $id");
        $data = $query->row();
        return $data->TenSP;
    }
    
    public function set_product_name($data)
    {  
       $query = $this->db->query("INSERT INTO sanpham (ID,idLoai,TenSP)
                                  VALUE ('".$data['id']."','".$data['type']."','".$data['name']."')");                        
       if($query)
            return true;
       else
            return false;
    }
    
    
    public function set_product_price($data)
    {
        $query = $this->db->query("INSERT INTO gia (idSP,Gia)
                                   VALUE ('".$data['id']."','".$data['price']."')");                        
       if($query)
            return true;
       else
            return false;
    }
    
    
    function set_product_info($data)
    {
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('1','".$data['id']."','".$data['cpu']."')");  
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('2','".$data['id']."','".$data['ram']."')");
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('3','".$data['id']."','".$data['hdd']."')"); 
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('4','".$data['id']."','".$data['vga']."')");
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('5','".$data['id']."','".$data['lcd']."')");
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('6','".$data['id']."','".$data['lan']."')");                                                             
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('7','".$data['id']."','".$data['weight']."')");
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('8','".$data['id']."','".$data['pin']."')");
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('9','".$data['id']."','".$data['os']."')");
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('10','".$data['id']."','".$data['optical']."')");
        $query = $this->db->query("INSERT INTO thongsosp (idTS,idSP,ThongSo)
                                   VALUE ('11','".$data['id']."','".$data['baohanh']."')");
    }
    
    function set_product_img_path($id,$img_data,$description)
    {
        $id_pic = date("hismd");
        $query = $this->db->query("INSERT INTO hinhanh (id,DuongDan,MoTa)
                                   VALUE ('".$id_pic."','./static/".$img_data['upload_data']['file_name']."','".$description."')"); 
        $query = $this->db->query("INSERT INTO anhlon (idSP,idAnh,Rong,Cao)
                                   VALUE ('".$id."','".$id_pic."','".$img_data['upload_data']['image_width']."','".$img_data['upload_data']['image_height']."')"); 
    }
    
    function set_product_thumb_path($id,$thumb_path,$description)
    {
        $id_pic = date("mdhis");
        $query = $this->db->query("INSERT INTO hinhanh (id,DuongDan,MoTa)
                                   VALUE ('".$id_pic."','".$thumb_path."','".$description."')"); 
        $query = $this->db->query("INSERT INTO thumbnail (idSP,idAnh)
                                   VALUE ('".$id."','".$id_pic."')"); 

    }
    
 }
 ?>